package com.szgr.baoyin.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.szgr.baoyin.R;
import com.szgr.baoyin.model.FilterItem;

import java.util.List;

/**
 * Created by yang on 15/11/5.
 */
public class FilterGridAdapter extends BaseAdapter {
    private Context mContext;
    private List<FilterItem> data;
    public FilterGridAdapter(Context context,List<FilterItem> data){
        mContext = context;
        this.data = data;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_filter_grid_view,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        FilterItem filterItem = data.get(position);
        holder.tv_name.setText(filterItem.getName());
        if(filterItem.isChecked()){
            holder.tv_name.setSelected(true);
            holder.tv_name.setTextColor(0xffffffff);
        }else{
            holder.tv_name.setSelected(false);
            holder.tv_name.setTextColor(0xff234b64);
        }
        return convertView;
    }

    public void setData(List<FilterItem> dataFirst) {
        data = dataFirst;
        notifyDataSetChanged();
    }

    class ViewHolder{
        TextView tv_name;

        public ViewHolder(View view){
            tv_name = (TextView) view.findViewById(R.id.text);
        }
    }
}
